package com.example.controller;

import com.example.domain.qo.user.DeletedQo;
import com.example.domain.qo.user.EditDataQo;
import com.example.domain.qo.user.EditQo;
import com.example.domain.qo.user.ListQo;
import com.example.domain.qo.user.SaveQo;
import com.example.domain.vo.user.EditDataVo;
import com.example.domain.vo.user.ListVo;
import com.example.service.UserService;
import com.example.tools.Result.ResultData;
import com.example.tools.Result.ResultStatus;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping("/admin/user")
@AllArgsConstructor
public class UserController {
    /***
     * UserService
     */
    private final UserService userService;

    @PostMapping("save")
    public ResultData<?> save(
            @RequestBody @Validated SaveQo saveQo) {
        userService.doSave(saveQo);
        return ResultData.makeMessage(ResultStatus.SUCCESS, "保存成功");
    }

    @PostMapping("edit")
    public ResultData<?> edit(
            @RequestBody @Validated EditQo editQo) {
        userService.doEdit(editQo);
        return ResultData.makeMessage(ResultStatus.SUCCESS, "修改成功");
    }

    @PostMapping("edit/data")
    public ResultData<EditDataVo> editDate(
            @RequestBody @Validated EditDataQo editDataQo) {
        EditDataVo editDataVo = userService.doEditData(editDataQo);
        return ResultData.makeData(ResultStatus.SUCCESS, editDataVo);
    }

    @PostMapping("list")
    public ResultData<ListVo> list(
            @RequestBody @Validated ListQo listQo) {
        ListVo listVo = userService.doList(listQo);
        return ResultData.makeData(ResultStatus.SUCCESS, listVo);
    }

    @PostMapping("delete")
    public ResultData<?> delete(
            @RequestBody @Validated DeletedQo deletedQo) {
        userService.doDelete(deletedQo);
        return ResultData.makeMessage(ResultStatus.SUCCESS, "删除成功");
    }


}
